class Events{
  constructor(){
    this.events={}
  }
}
Events.prototype.extend=function(events,obj) {
  let that=this;
  obj=obj||{};
  Object.assign(obj,{on:this.on,emit:this.emit});
  events.forEach(name=>{
    obj["on"+name]=function(callback) {
      that.on(name,callback);
    },
    obj["un"+name]=function(callback) {
      that.un(name,callback);
    }
  })
  return obj;
}
Events.prototype.on=function(name,callback) {
  if(!callback){
    return;
  }
  this.events[name]=this.events[name]||[];
  this.events[name].push(callback);
};
Events.prototype.un=function(name,callback) {

   this.events[name]=[];
  
};
Events.prototype.emit=function(name) {
    let that=this;
    let args=Array.prototype.slice.call(arguments,1);
    console.log(this.events);
    let events=this.events[name];
    if(!events){
      return;
    }
    events.forEach(callback => {
      callback.apply(that,args);
    });
};
module.exports={ createEvents() {
      return new Events();
  }
};